package collection;

import java.util.ArrayList;
import java.util.List;

/**
 * @since Oct 28, 2017
 * When List is passed as a parameter, its reference is passed?
 */
class A {

    private int id;

    private String name;

    public A() {
    }

    public A(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

public class ListTest {

    private void modifyList(List<A> list) {
        for (A a : list) {
            a.setId(3);
        }

        list.add(new A(1, "1"));
    }

    private void modifyString(String s) {
        s += "b";
    }

    public static void main(String[] args) {
        List<A> list = new ArrayList<>();
        list.add(new A(1, "1"));
        list.add(new A(2, "2"));

        ListTest listTest = new ListTest();
        listTest.modifyList(list);

        for (A a : list) {
            //[out]:331
            System.out.print(a.getId());
        }

        String s = "s";
        listTest.modifyString(s);
        //[out]:s
        System.out.println(s);

    }
}
